package com.kayt.cyberBar.cuser.business.dao.impl;

import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.dao.EntityDao;
import com.kayt.cyberBar.cuser.business.dao.ICyberBaseTaskAttachDao;
import com.kayt.cyberBar.cuser.business.entity.po.BCyberBaseTaskAttach;

@Repository("iCyberBaseTaskAttachDao")
public class CyberBaseTaskAttachDaoImpl implements ICyberBaseTaskAttachDao {
	
	@Autowired
	private EntityDao entityDao;

	@Override
	public Long addAttach(BCyberBaseTaskAttach attach) throws SQLException {
		if (attach != null) {
			return this.entityDao.save(attach);
		}
		return 0L;
	}
	
	@Override
	public void updateAttach (BCyberBaseTaskAttach attach) throws SQLException {
		if (attach != null) {
			this.entityDao.update(attach);
		}
	}
	
	@Override
	public int deleteAttach (String attach) {
		if (attach != null) {
			this.entityDao.deleteDetached(attach);
			return 0;
		}
		return -1;
	}
	
	@Override
	public BCyberBaseTaskAttach getAttach (String attachId) {
		BCyberBaseTaskAttach bAttachDetailItem = null;
		if (attachId != null) {
			Long id;
			try {
				id = Long.parseLong(attachId);
			} catch (Exception e) {
				return null;
			}
			bAttachDetailItem = this.entityDao.findById(id, BCyberBaseTaskAttach.class);
		}
		return bAttachDetailItem;
	}
	
	@Override
	public BCyberBaseTaskAttach getAttachByCode (String code) throws SQLException {
		BCyberBaseTaskAttach bAttachDetailItem = null;
		if (code != null) {
			bAttachDetailItem = this.entityDao.getObj(BCyberBaseTaskAttach.class, " o.code=? ", new Object[]{code});
		}
		return bAttachDetailItem;
	}
	
	@Override
	public PageData<BCyberBaseTaskAttach> getAttachList (int pageNum, int pageSize, String hql, Object[] params, LinkedHashMap<String, String> attachMap) throws SQLException {
		return this.entityDao.getPagingData(BCyberBaseTaskAttach.class, pageNum, pageSize, hql, params, attachMap);
	}
	
	@Override
	public List getAttachListByHql(int pageNum, int pageSize, String hql, Object[] params) throws SQLException {
		return this.entityDao.getPagingDataByHql(pageNum, pageSize, hql, params);
	}
}
